/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#pragma once

#include "VssBase.h"

#include <vector>

class VssRestore : public VssBase {
public:
	VssRestore();
    ~VssRestore();
    bool Restore(const std::string& backupXmlPath, const std::string& writerXmlPath, const std::string& guid, \
        const std::string& dataRepoPath, const std::string& restorePath);
private:
	bool RestoreInitalization(BSTR backupMetadataDocument);
    bool ActualRestoration(const std::string& dataRepoPath, const std::string& restorePath);
    bool RestoreCleanUpAndTermination();

    bool FetchWriterMetadata(VSS_ID exchangeWriterID);

    CComPtr<IVssBackupComponents> m_ppBackupComponent;
    std::vector<VSS_ID> m_pidWriterInstances;
    std::vector<CComPtr<IVssExamineWriterMetadata>> m_ppExmaineWriterMetadata;
    UINT m_pcWriterComponents;

	// Exchange Writer相关
    CComPtr<IVssExamineWriterMetadata> m_ppExchangeExamineWriterMetadata;
    CComPtr<IVssWriterComponentsExt> m_ppExchangeWriterComponentsExt;
    VSS_ID m_pidExchangeInstance;
    VSS_ID m_pidExchangeWriter;
    CComPtr<IVssWMComponent> ppExchangeWriterSelectedWMComponent;

    std::vector<BSTR> m_bstrPathToRestore;

    // 联调临时加入
    BSTR m_backupMetadataDocumentWriter;
    CComPtr<IVssExamineWriterMetadata> m_ppExchangeWriterComponentPlus;
    bool RestorePreparetionV2(VSS_ID exchangeWriterID, BSTR targetDatabaseGuid);
    void GetFileList(std::string dataDir, std::vector<std::wstring> &fileList);
    std::vector<BSTR> m_bstrFilenameToRestore;

    // 联调后续应加入
    BSTR m_backupMetadataDocument;
    BSTR m_exchangeWriterMetadataDocument;
    BSTR m_targetDatabaseGuid;
};